package com.maweis;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import org.apache.xmlrpc.XmlRpcClient;

import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Date;
import java.util.Hashtable;
import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: peter
 * Date: 2007-9-29
 * Time: 8:54:03
 */
public class BlogAction extends AnAction {


    public void actionPerformed(AnActionEvent e) {
        Application application = ApplicationManager.getApplication();
        BlogApplicationComponent helloWorldComponent =
                application.getComponent(BlogApplicationComponent.class);
        helloWorldComponent.sayHello();
    }


    public static void main(String[] args) {
        XmlRpcClient client = null;
        try {
            client = new XmlRpcClient(new URL("http://maweis.com/xmlrpc.php"));

        } catch (MalformedURLException exp) {
// TODO Auto-generated catch block
            exp.printStackTrace();
        }
        Vector v = new Vector();
        v.add("1");
        v.add("username");
        v.add("password");
        Hashtable hashtable = new Hashtable();
        hashtable.put("title", "IDEA blog plugin");
        hashtable.put("description", "the content from idea, the best rad tools");
        Date date = new Date(System.currentTimeMillis());
        hashtable.put("dateCreated", date);
        String category[] = new String[1];
        category[0] = "life";
        hashtable.put("categories", category);
        v.add(hashtable);
        v.add("true");
        try {

            Object result = client.execute("metaWeblog.newPost", v);
            System.out.println("received:" + result);
        } catch (Exception exp) {

            System.out.println(exp);
        }

    }


}